﻿<?php
/**
 * 添加题目功能
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');


$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$request=$_POST;
if(empty($request['contest_no'])||empty($request['name'])||empty($request['sign_begin_time'])||empty($request['sign_end_time'])||empty($request['begin_time'])
   ||empty($request['end_time']) ||empty($request['addtime']) ||empty($request['status'])||empty($request['summary'])){
    $_SESSION['errors']="添加失败请注意格式";
   	header( 'Location:../manager/manager_contest_add.php' );
}

$tpl->assign('admin', $_SESSION['admin']);
try{
 $db=  db_connect();
 $contest=new contest_process($db);
 $contest->load('contest_no',$request['contest_no']);
 $contest->set('contest_no',$request['contest_no']);
 $contest->set('name',$request['name']);
 $contest->set('sign_begin_time',$request['sign_begin_time']);
 $contest->set('sign_end_time',$request['sign_end_time']);
 $contest->set('begin_time',$request['begin_time']);
 $contest->set('end_time',$request['end_time']);
 $contest->set('addtime',$request['addtime']);
 $contest->set('summary',$request['summary']);
 $contest->set('status',$request['status']);
 $contest->save(); 
 header( 'Location:../manager/manager_contest_detail.php?no='.$request['contest_no'] );
}
catch(Exception $e){
     
     $_SESSION['errors']="添加失败请注意格式".$e;
	 header( 'Location:../manager/manager_contest_alter.php?no='.$request['contest_no']);
}


